﻿@{
    Layout = null;
}
@model SRF.UI.DataSource
@using SRF.UI.Html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="@Url.Content("~/Content/style.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui/js/jquery.ui.core.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui/js/jquery.ui.widget.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui/js/jquery.ui.mouse.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui/js/jquery.ui.draggable.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/bootstrap/js/bootstrap-modal.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/dialog.js")" type="text/javascript"></script>
    <script type="text/javascript">
        var DataRuleId = "@ViewBag.DataRuleId";
        function search() {
            $(".searchbar").search();
        }
        function resetSearch() {
            //TODO:重设搜索条件
            $("#name").val("");
            search();
        }
        function openEditor(action, id) {
            var url, title;
            var params = { DataRuleId: DataRuleId };
            switch (action) {
                case "add":
                    {
                        url = buildUrl("ItemEdit", params);
                        title = "新增数据规则";
                    }
                    break;
                case "update":
                    {
                        params.id = id;
                        url = buildUrl("ItemEdit", params);
                        title = "修改数据规则";
                    }
                    break;
                case "delete":
                    {
                        $.confirm("您确定要删除该数据规则吗？", "确认删除", function (returnValue) {
                            if (returnValue == "ok") {
                                url = "deleteitem";
                                $.get(url, { id: id }, function (data) {
                                    if (data) {  //发生异常
                                        alert(data);
                                    }
                                    else {
                                        location.reload();
                                    }
                                });
                            };
                        });
                        return;
                    }
                    break;
                case "view":
                    {
                        url = "ItemView/" + id;
                        title = "查看数据规则";
                        $.dialog({
                            url: url,
                            title: title,
                            height: 300,
                            width: 580,
                            buttons: {
                                "关闭": {
                                    "class": "btn btn-primary",
                                    "data-dismiss": 'modal'
                                }
                            },
                            loading: function () {
                                $(this).iframeLoading();
                            }
                        });
                        return;
                    }
                    break;
            }
            //新增\修改
            $.dialog({
                url: url,
                title: title,
                height: 300,
                width: 580,
                callback: function (returnValue) {
                    location.reload();
                },
                loading: function () {
                    $(this).iframeLoading();
                }
            });
        }
        function onDialogClosed(id, returnValue) {
            if (returnValue == true)
                location.reload();
        }

        $(function () {
            $(".searchbar").initSearch();
        })
    </script>
</head>
<body>
    <div class="toolbar btn-group" style="margin-right: 5px; float: right;">
        <input type="button" value="新增" class="btn btn-primary btn-small" style="float: right"
            onclick="openEditor('add');" />
    </div>
    <div class="searchbar control-group" style="margin-bottom: 0px">
        <div class="controls" style="margin-left: 0px">
            <!--搜索条件-->
            <label class="" for="text" style="display: inline-block">
                名称:</label>
            @Html.TextBox("name", ViewData["name"])
            <input type="button" class="btn btn-primary btn-small" value="搜索" onclick="search();" /><input
                type="button" class="btn btn-small" value="重置" onclick="resetSearch();" /></div>
    </div>
    <div>
        <table class="grid table table-striped table-bordered bootstrap-datatable datatable">
            <thead>
                <tr>
                    @Html.GridHeader("名称", "text")
                    @Html.GridHeader("条件", "Condition")
                    @Html.GridHeader("排序", "rank")
                    <th>
                        描述
                    </th>
                    <th>
                        操作
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (System.Data.DataRow row in Model.Rows)
                {  
                    <tr>
                        <td style="width: 150px">@row["Name"]
                        </td>
                        <td style="width: 250px">@row["Condition"]
                        </td>
                        <td class="center" style="width: 60px">@row["Rank"]
                        </td>
                        <td>@row["Remark"]
                        </td>
                        <td class="action" style="width: 80px">
                            <a class="icon-edit" href="javascript:openEditor('update','@row["Id"]');" title="修改">
                            </a><a class="icon-book" href="javascript:openEditor('view','@row["Id"]');" title="查看">
                            </a><a class="icon-remove" href="javascript:openEditor('delete','@row["Id"]');" title="删除">
                            </a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        @if (this.Model.PerPageSize > 0)
        { 
            @Html.PageBar(this.Model)
        }
    </div>
</body>
</html>
